package 剑指offer;

import java.util.Stack;

public class _30包含min函数的栈 {
    private Stack<Integer> data_stack;
    private Stack<Integer> min_stack;

    public _30包含min函数的栈() {
        data_stack = new Stack<>();
        min_stack = new Stack<>();
    }

    public void push(int x) {
        data_stack.push(x);
        if(min_stack.empty() || x < min_stack.peek()){
            min_stack.push(x);
        }else {
            min_stack.push(min_stack.peek());
        }
    }

    public void pop() {
        data_stack.pop();
        min_stack.pop();
    }

    public int top() {
        return data_stack.peek();
    }

    public int min() {
        return min_stack.peek();
    }
}
